home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 March
/
EnigmA AMIGA RUN 05 (1996)(G.R. Edizioni)(IT)[!][issue 1996-03][Skylink CD IV].iso
/
earcd
/
program
/
ixemlsrc.lha
/
ixemul
/
stdlib
/
system.c
< prev
Wrap
C/C++ Source or Header
|
1995-12-23
|
3KB
|
107 lines
/*
* This file is part of ixemul.library for the Amiga.
* Copyright (C) 1991, 1992 Markus M. Wild
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define KERNEL
#include "ixemul.h"
#include "kprintf.h"
#include <sys/wait.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
/* 2.0 support */
#include <utility/tagitem.h>
#include <dos/dostags.h>
#define STACKNAME ("IXSTACK") /* Environment variable for stack size */
#define STACKSIZE (16384) /* Minimum stack size to use */
int get_stack_size(struct Process *proc)
{
struct CommandLineInterface *CLI;
int stack_size;
char *tmp;
CLI = BTOCPTR (proc->pr_CLI);
if ((tmp = getenv (STACKNAME)))
stack_size = atoi (tmp);
else
stack_size = CLI ? CLI->cli_DefaultStack * 4 : proc->pr_StackSize;
if (stack_size < STACKSIZE)
return STACKSIZE;
return stack_size;
}
int system (const char *cmd)
{
int rc = -1, err = 0;
int stack_size;
struct Process *me;
int omask;
if (cmd == NULL)
return 1;
/* I retry with our new signal mechanism ;-) */
omask = syscall (SYS_sigsetmask, ~0);
me = (struct Process *)FindTask(0);
stack_size = get_stack_size(me);
/* limited support to allow starting of files in the current directory
* with `./foo'. The better approach would use the __plock() trick to
* parse the command, LoadSeg it. But then this approach would have to
* do the whole redirection stuff on its own.. */
while (isspace (*cmd)) cmd++;
while (cmd[0] == '.' && cmd[1] == '/') cmd += 2;
/* convert absolute path names if enabled in ixemulbase */
if ((ix.ix_flags & ix_translate_slash) && cmd[0] == '/')
{
char *path_sep = NULL;
cmd++;
if ((path_sep = strchr (cmd, '/'))) *path_sep = ':';
}
{
struct TagItem tags [] =
{
/* a stack of 4K is generally ways too small.. */
{ NP_StackSize, stack_size, },
{ TAG_END, 0, }
};
rc = SystemTagList ((UBYTE *)cmd, tags);
err = __ioerr_to_errno (IoErr ());
syscall (SYS_sigsetmask, omask);
if (rc > 128)
errno = EINTR;
else
errno = err;
KPRINTF (("&errno = %lx, errno = %ld\n", &errno, errno));
/* according to the BSD manual, system() should return the `exit status'
* of the shell, the implementation returns the wait-status. So I return
* an artificial wait status for now ...
*/
return (rc >= 128) ? W_EXITCODE (0, rc & 0x7f) : W_EXITCODE (rc, 0);
}
}